package com.stn.zjx.givingtreasure.net.impl;

import android.annotation.SuppressLint;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.stn.zjx.givingtreasure.net.CheckVersionApi;
import com.stn.zjx.givingtreasure.net.UserAddressApi;
import com.stn.zjx.givingtreasure.net.UserBankCardApi;
import com.stn.zjx.givingtreasure.utils.ToolsUtils;

import org.json.JSONObject;

public class UserBankCardNetImpl {



    /**

     * @param tag 标签
     * @param callback 请求回调
     */
    public static void query_support_bank_card(
                                                 String tag, StringCallback callback){

        OkGo.<String>post(UserBankCardApi.query_support_bank_card)
                .tag(tag)
                .cacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .cacheKey(tag)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .isSpliceUrl(true)
                .upJson("")
                .execute(callback);

    }

    /**
     * @apiNote 新增银行卡
     * @param token token

     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void add_bank_card(String token,
                                   String userRealName,
                                   String userIdCard,
                                   String userBankCardNo,
                                   String userPhone,
                                   String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userRealName",userRealName);
            jsonObject.put("userIdCard",userIdCard);
            jsonObject.put("userBankCardNo",userBankCardNo);
            jsonObject.put("userPhone",userPhone);

            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserBankCardApi.add_bank_card)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }
    /**
     * @apiNote 查询银行卡
     * @param token token

     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void query_bank_card_by_user_id(String token,
                                     String tag, StringCallback callback){

        OkGo.<String>post(UserBankCardApi.query_bank_card_by_user_id)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .cacheTime(CacheEntity.CACHE_NEVER_EXPIRE)
                .cacheKey(tag)
                .cacheMode(CacheMode.FIRST_CACHE_THEN_REQUEST)
                .params("token",token)
                .execute(callback);
    }

    /**
     * @apiNote 删除银行卡
     * @param token token

     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void delete_bank_card(String token,
                                     Integer userBankCardId,
                                     String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userBankCardId",userBankCardId);

            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserBankCardApi.delete_bank_card)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }

    /**
     * @apiNote 修改银行卡
     * @param token token

     * @param tag 标签
     * @param callback 请求回调
     */
    @SuppressLint("CheckResult")
    public static void modify_bank_card(String token,
                                        Integer userBankCardId,
                                        String userIdCard,
                                        String userRealName,
                                        String userPhone,
                                        String tag, StringCallback callback){
        String data="";
        JSONObject jsonObject=new JSONObject();
        try {
            jsonObject.put("userBankCardId",userBankCardId);
            jsonObject.put("userIdCard",userIdCard);
            jsonObject.put("userRealName",userRealName);
            jsonObject.put("userPhone",userPhone);
            data= ToolsUtils.getEncryptionParams(jsonObject.toString());
        } catch (Exception e) {
            e.printStackTrace();

        }
        OkGo.<String>post(UserBankCardApi.modify_bank_card)
                .tag(tag)
                .isSpliceUrl(true)
                .upJson("")
                .params("token",token)
                .params("data",data)
                .execute(callback);
    }

}
